package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageBean;
import com.zzyl.dto.RoleDto;
import com.zzyl.entity.Role;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.RoleMapper;
import com.zzyl.service.RoleService;
import com.zzyl.vo.RoleVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class RoleServiceImpl implements RoleService {
    private final RoleMapper roleMapper;

    /**
     * @param roleDto
     */
    @Override
    public void insert(RoleDto roleDto) {
        if (BeanUtil.isEmpty(roleDto)) {
            throw new BaseException(BasicEnum.PARAMS_ERROR);
        }
        roleMapper.insert(roleDto);
    }

    /**
     * @param roleDto
     */
    @Override
    public void uodateRole(RoleDto roleDto) {
        if (BeanUtil.isEmpty(roleDto)) {
            throw new BaseException(BasicEnum.PARAMS_ERROR);
        }
        roleMapper.uodateRole(roleDto);
        String[] checkedDeptNos = roleDto.getCheckedDeptNos();
        String[] checkedResourceNos = roleDto.getCheckedResourceNos();
    }

    /**
     * @param roleDto 
     * @return
     * 
     * 
     */
    @Override
    public PageBean<RoleVo> queryRolePage(Integer pageNum, Integer pageSize, RoleDto roleDto) {
        pageNum = Math.max(pageNum,1);
        pageSize = Math.max(pageSize,10);
        PageHelper.startPage(pageNum,pageSize);
       Role role =BeanUtil.toBean(roleDto,Role.class);
        Page<Role> page = roleMapper.selectPage(role);
        return PageBean.of(page, RoleVo.class);
    }
}
